package net.caixiaomi.info.adapter;

import android.support.annotation.LayoutRes;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import net.caixiaomi.info.R;
import net.caixiaomi.info.app.CommonApp;
import net.caixiaomi.info.base.quickadapter.BaseQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.helper.AppHelper;
import net.caixiaomi.info.interfaces.SimpleEqualRatioTarget;
import net.caixiaomi.info.model.MessageItem;

/**
 * 消息
 */

public class MessageAdapter extends BaseQuickAdapter<MessageItem, BaseViewHolder> {

    public MessageAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageItem item) {
        try {
            helper.setText(R.id.title, item.getTitle());
            helper.setText(R.id.time, item.getSendTime());
            helper.setText(R.id.summary, item.getContentDesc());
            RequestOptions options = new RequestOptions().centerCrop();
            int width = AppHelper.getScreenWidth(CommonApp.getInstance());
            int height = (int) (AppHelper.getScreenWidth(CommonApp.getInstance()) / 2.8);
            Glide.with(CommonApp.getInstance()).asBitmap().apply(options).load(item.getContentUrl()).into(new SimpleEqualRatioTarget((ImageView) helper.getView(R.id.image), width, height));
            helper.addOnClickListener(R.id.btn_look);
            if (helper.getAdapterPosition() == 0) {
                RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) helper.itemView.getLayoutParams();
                layoutParams.topMargin = (int) CommonApp.getInstance().getResources().getDimension(R.dimen.padding_12);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
